package crowx.android.AndCellTrack;

import java.util.*;
import android.os.RemoteException;

class CellTrackStateObservable extends IAndCellTrackServiceBase.Stub implements ICellTrackStateObserver {
	private static final String TAG = "AndCellTrack";
	
	private CellInfo cellInfo;
	protected List<ICellTrackStateObserver> observers = new ArrayList<ICellTrackStateObserver>();
	
	CellTrackStateObservable(CellInfo cellInfo) {
		this.cellInfo = cellInfo;
	}
	
	@Override
	public void registerObserver(ICellTrackStateObserver observer) throws RemoteException {
		android.util.Log.d(TAG, "CellTrackStateObservable.registerObserver");
		observers.add(observer);
	}

	@Override
	public void unregisterObserver(ICellTrackStateObserver observer) throws RemoteException {
		android.util.Log.d(TAG, "CellTrackStateObservable.unregisterObserver");
		observers.remove(observer);
	}

	@Override
	public CellInfo getCellInfo() throws RemoteException {
		return cellInfo;
	}
	
	/*@Override
	public void onLocationChanged(Location location) {
		Iterator<ICellTrackStateObserver> it = observers.iterator();
		while(it.hasNext()) {
			try {
				it.next().onLocationChanged(location);
			} catch (RemoteException e) {
				android.util.Log.e(TAG,"CellTrackStateObserver.onLocationChanged",e);
			}
		}
	}*/

	@Override
	public void onStateChanged(CellInfo cellInfo) {
		Iterator<ICellTrackStateObserver> it = observers.iterator();
		while(it.hasNext()) {
			try {
				it.next().onStateChanged(cellInfo);
			} catch (RemoteException e) {
				android.util.Log.e(TAG,"CellTrackStateObserver.onStateChanged",e);
			}
		}
	}
}
